/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import model.Vare;
import model.Varegruppe;
import view.GUI;

/**
 *
 * @author Morten J, Morten B & Jonas
 */
public class VareHandler {

    private static final ArrayList<Vare> vareListe = new ArrayList<>();
    private final String select;
    private ResultSet rs;
    private Vare vare;

    public VareHandler() {

	select = "select * from vare";

	try {
	    rs = Main.getDbConnection().select(select);
	    Varegruppe varegruppe = null;
	    while (rs.next()) {
		for (Varegruppe vg : VaregruppeHandler.getVareGruppeListe()) {
		    if (rs.getInt("fk_vareGruppe") == vg.getVareGruppeNr()) {
			varegruppe = vg;
		    }
		}
		vare = new Vare(rs.getInt("vareNr"), rs.getString("vareNavn"), rs.getString("leverandoer"),
			rs.getDouble("salgsPrisKr"), rs.getDouble("salgsPrisEu"),
			rs.getBoolean("medlemsPris"), rs.getInt("rabat"),
			rs.getInt("varebeholdning"), rs.getBoolean("aktuel"),
			varegruppe);
		vareListe.add(vare);
	    }
	} catch (SQLException ex) {
	    GUI.getGuiHandler().setFeedbackMessage(" ved indlæsning af vare");
	}
    }

    public static ArrayList<Vare> getVareListe() {
	return vareListe;
    }

}
